import Vue from "vue";
import App from "./App";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import "@/assets/css/style.css";
import store from "./vuex/store";
import Vuex from "vuex";
import router from "@/router";
import myFilter from "@/filters/index.js";
import * as load from "@/utils/loading.js";
import { getCookie } from "@/utils/util.js";
import "font-awesome/css/font-awesome.min.css";

Vue.use(ElementUI);
Vue.use(Vuex);

Vue.prototype.$load = load;

for (let key in myFilter) {
  Vue.filter(key, myFilter[key]);
}

router.beforeEach((to, from, next) => {
  if (to.path == "/login") {
    sessionStorage.removeItem("user");
  }
  let token = getCookie("token");
  if (token === "" && to.path != "/login") {
    next({ path: "/login" });
  } else {
    next();
  }
});

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
